package com.leo.blog.web.menu;


import com.leo.blog.service.TbMenuService;
import com.leo.blog.util.TreeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Classname MenuController
 * @Description TODO
 * @Date 2023/4/14 11:39
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RequestMapping("/menu")
@RestController
public class MenuController {

    @Autowired
    private TbMenuService tbMenuService;

    @GetMapping("/tree")
    public Map<String,Object> treeList(){
        List<Map<String,Object>>objects=tbMenuService.listMaps();
        List<Map<String,Object>> objs=TreeUtils.listToTree("id","pid","child",objects);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("data",objs);
        return map;
    }
}
